package com.hibernate.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.hibernate.service.VocabularyService;

@Controller
public class VocabularyController {
	private static final long serialVersionUID = 1L;

	@Autowired
	VocabularyService vocabularyService;

	@RequestMapping(value = "/voc")
	public ModelAndView handleRequest(@RequestParam("id") int vocId, Model model) {
		// Objekte erzeugen
		model.addAttribute("model", vocabularyService.getVocabulary(vocId , 1, 2));

		return new ModelAndView("Vocabulary");
	}

	@RequestMapping(value = "/allVoc")
	public ModelAndView getVocabularyList(
			@RequestParam("s") int sourceLang,
			@RequestParam("t") int targetLang, Model model) {
		// Objekte erzeugen
		model.addAttribute("model",
				vocabularyService.getAllVocabularies(sourceLang, targetLang));
		model.addAttribute("sLang",
				vocabularyService.getSourceLang());
		model.addAttribute("tLang",
				vocabularyService.getTargetLang());
		System.out.println(vocabularyService.getSourceLang());
		return new ModelAndView("Overview");
	}
}
